import 'package:flutter/material.dart' hide MenuController;
import 'package:flutter_soundmagus/util/util.dart';
import 'package:get/get.dart';

import 'menu_controller.dart';

class MenuView extends GetView<MenuController> {
  final bool left;
  const MenuView(this.left, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      left: false,
      right: false,
      bottom: false,
      child: GestureDetector(
        onTap: () => Get.back(),
        child: Container(
          color: Colors.black.withOpacity(0.6),
          child: Row(
            children: [
              if (left) _buildMenuBox(left: true),
              Spacer(),
              if (!left) _buildMenuBox(left: false),
            ],
          ),
        ),
      ),
    );
  }

  void onMenu(Menu menu) => controller.onMenu(menu);

  Widget _buildMenuBox({bool left = true}) {
    var centerY = Get.height / 2, space = Get.height / 6;
    if (left) {
      return Stack(
        children: [
          Image.asset(
            'menu_bg_left'.img,
            scale: 3,
            // colorBlendMode: BlendMode.colorDodge,
            // color: Colors.red,
          ),
          Positioned(
            child: GestureDetector(
              child: 'icon_menu'.uiimg,
              onTap: () => onMenu(Menu.close),
            ),
            top: 20,
            right: 180,
            // left: 0,
          ),
          Positioned(
            child: GestureDetector(
              child: 'icon_tab_home_s'.uiimg,
              onTap: () => onMenu(Menu.home),
            ),
            top: centerY - space - 2 * 25,
            right: 120,
          ),
          Positioned(
            child: GestureDetector(
              child: 'icon_save'.uiimg,
              onTap: () => onMenu(Menu.save),
            ),
            top: centerY - 25,
            right: 100,
          ),
          Positioned(
            child: GestureDetector(
              child: 'icon_upload'.uiimg,
              onTap: () => onMenu(Menu.upload),
            ),
            top: centerY + space - 25,
            right: 110,
          ),
          Positioned(
            child: GestureDetector(
              child: 'icon_setting'.uiimg,
              onTap: () => onMenu(Menu.setting),
            ),
            top: Get.height - space - 25 + 10,
            right: 150,
          ),
        ],
      );
    }
    return Stack(
      alignment: Alignment.topRight,
      children: [
        'menu_bg_right'.uiimg,
        Positioned(
          child: GestureDetector(
            child: 'icon_tab_summing'.uiimg,
            onTap: () => onMenu(Menu.summing),
          ),
          top: 20,
          left: 145,
        ),
        Positioned(
          child: GestureDetector(
            child: 'icon_tab_cross'.uiimg,
            onTap: () => onMenu(Menu.cross),
          ),
          top: centerY - space - 25,
          left: 105,
        ),
        Positioned(
          child: GestureDetector(
            child: 'icon_tab_delay'.uiimg,
            onTap: () => onMenu(Menu.delay),
          ),
          top: centerY - 25,
          left: 100,
        ),
        Positioned(
          child: GestureDetector(
            child: 'icon_tab_gain'.uiimg,
            onTap: () => onMenu(Menu.gain),
          ),
          top: centerY + space - 25,
          left: 110,
        ),
        Positioned(
          child: GestureDetector(
            child: 'icon_tab_eq'.uiimg,
            onTap: () => onMenu(Menu.eq),
          ),
          top: Get.height - space - 25 + 10,
          left: 150,
        ),
      ],
    );
  }
}
